package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.api.mapper.BlackListMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 黑名单管理服务接口实现类
 */
@DubboService
public class BlackListApiImpl implements BlackListApi{

    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 分页查询黑名单列表数据
     *
     * @param page
     * @param pageSize
     * @param userId
     * @return
     */
    @Override
    public PageResult<BlackList> findPageBlacklist(Long page, Long pageSize, Long userId) {
        //1构造分页参数对象
        IPage<BlackList> queryPage = new Page<>(page,pageSize);
        //2,构造查询条件
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        //3执行分页查询
        IPage<BlackList> pg = blackListMapper.selectPage(queryPage, queryWrapper);
        //4构造PageResult返回
        return new PageResult<>(pg.getTotal(),pageSize,pg.getPages(),page,pg.getRecords());
    }

    /**
     * 黑名单 - 移除
     * uid:黑名单用户id
     *
     * @param blackUserId
     * @param userId
     */
    @Override
    public void deleteBlacklistById(Long blackUserId, Long userId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("black_user_id",blackUserId).eq("user_id",userId);
        blackListMapper.delete(queryWrapper);
    }
}
